﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pavilion
{
    public class DrawVisibilityGroup
    {
        private List<DrawItem> drawItemList;
        private bool isVisible;

        public DrawVisibilityGroup()
        {
            drawItemList = new List<DrawItem>();
            isVisible = true;
        }

        public void Add(DrawItem drawItem)
        {
            if (drawItemList.Contains(drawItem))
                return;

            drawItem.Disposed += new Action<DrawItem>(DrawItem_Disposed);
            drawItemList.Add(drawItem);
        }

        public void Remove(DrawItem drawItem)
        {
            if (drawItemList.Remove(drawItem))
                drawItem.Disposed -= new Action<DrawItem>(DrawItem_Disposed);
        }

        public bool IsVisible
        {
            get { return isVisible; }
            set
            {
                if (isVisible == value)
                    return;

                foreach (DrawItem drawItem in drawItemList)
                    drawItem.IsVisible = value;
            }
        }

        private void DrawItem_Disposed(DrawItem drawItem)
        {
            Remove(drawItem);
        }
    }
}
